package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.Function;
import com.oocl.euc.core.maintenance.model.FunctionAuth;
import com.oocl.euc.core.maintenance.repository.FunctionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class FunctionBuilder {
    private Function function;

    @Autowired
    private FunctionRepository functionRepository;

    public FunctionBuilder defaultBuilder() {
        this.function = new Function();
        this.function.setFunctionName("Test function name");
        this.function.setFunctionDesc("Test function desc");
        this.function.setRoleRelated(true);
        this.function.setStatusRelated(true);
        this.function.setActive(true);
        return this;
    }

    public FunctionBuilder withFunctionAuth(Set<FunctionAuth> functionAuthSet) {
        function.setFunctionAuthSet(functionAuthSet);
        return this;
    }

    public FunctionBuilder withRoleRelated(boolean isRoleRelated) {
        function.setRoleRelated(isRoleRelated);
        return this;
    }

    public FunctionBuilder withStatusRelated(boolean isStatusRelated) {
        function.setStatusRelated(isStatusRelated);
        return this;
    }

    public FunctionBuilder withFunctionName(String functionName) {
        function.setFunctionName(functionName);
        return this;
    }

    public FunctionBuilder withFunctionDesc(String functionDesc) {
        function.setFunctionDesc(functionDesc);
        return this;
    }


    public Function create() {
        return function;
    }

    public Function saveToDB() {
        functionRepository.save(function);
        return function;
    }
}
